import {
  createRouter,
  createWebHashHistory // 您使用的是 createWebHashHistory
} from "vue-router";

import login from "../views/login/index.vue";
import Layout from "../layout/index.vue";

// ========================================================================
// 导入我们新定义的业务页面组件
// 请确保这些文件路径正确，并在项目中创建这些文件
import DashboardView from '../views/dashboard/index.vue'; // 假设仪表盘放在 views/dashboard/index.vue
import DataPreprocessingView from '../views/dataPreprocessing/index.vue'; // 数据处理与特征工程
// import ModelTrainingView from '../views/modelTraining/index.vue';     // 模型训练与评估
import ErrorAnalysisView from '../views/errorAnalysis/index.vue';      // 预测与误差分析
// ========================================================================

const routes = [
  {
    path: "/login",
    name: "Login", // 建议name使用字符串，而不是直接组件引用
    component: login,
  },
  {
    path: "/",
    component: Layout,
    name: "container",
    redirect: "/dashboard", // 将默认重定向改为我们的仪表盘页面
    meta: {
      requiresAuth: true,
      name: "主页概览", // 可以将这个层级的name改为更通用的“主页概览”
    },
    children: [
      // ========================================================================
      // 新增的四个核心业务页面
      {
        path: "/dashboard", // 负荷预测仪表盘
        name: "Dashboard",
        component: DashboardView,
        meta: {
          requiresAuth: true,
          name: "负荷预测仪表盘",
        },
      },
      {
        path: "/data-preprocessing", // 数据处理与特征工程
        name: "DataPreprocessing",
        component: ()=> import("../views/form/baseForm.vue"), // 仍然指向同一个页面，内部根据meta或query参数判断展示内容
        meta: {
          requiresAuth: true,
          name: "数据集划分",
        },
      },
     
      {
        path: "/error-analysis", // 预测与误差分析
        name: "ErrorAnalysis",
        component: ErrorAnalysisView,
        meta: {
          requiresAuth: true,
          name: "预测与误差分析",
        },
      },
      // ========================================================================

      // 您原有的深度学习模型子路由
      {
        path: "/deepLearning", // 添加一个父级路由来组织深度学习模型
        name: "DeepLearning",
        component: () => import("../views/empty-layout.vue"), // 可以是一个空的Layout组件或父级路由的占位符
        meta: {
          requiresAuth: true,
          name: "深度学习模型",
        },
        children: [
          {
            path: "lstm", // 注意这里是相对路径
            name: "lstm",
            component: () => import("../views/deepLearning/lstm.vue"),
            meta: {
              requiresAuth: true,
              name: "LSTM网络",
            },
          },
          {
            path: "gru", // 注意这里是相对路径
            name: "gru",
            component: () => import("../views/deepLearning/gru.vue"),
            meta: {
              requiresAuth: true,
              name: "GRU网络",
            },
          },
        ]
      },


      // 您原有的传统机器学习模型子路由
      {
        path: "/traditional-ml", // 修改为更清晰的路径，避免与顶层/traditional冲突
        name: "TraditionalML",
        component: () => import("../views/empty-layout.vue"), // 可以是一个空的Layout组件或父级路由的占位符
        meta: {
          name: "传统机器学习模型"
        },
        children: [
          // {
          //   path: "randomForest", // 相对路径
          //   name: "randomForest",
          //   component: () => import("../views/traditional/randomForest.vue"),
          //   meta: {
          //     requiresAuth: true,
          //     name: "随机森林回归"
          //   }
          // },
          {
            path: "xgboost", // 相对路径
            name: "xgboost",
            component: () => import("../views/traditional/xgboost.vue"),
            meta: {
              requiresAuth: true,
              name: "XGBoost回归"
            }
          },
          // {
          //   path: "decisionTree", // 相对路径
          //   name: "decisionTree",
          //   component: () => import("../views/traditional/decisionTree.vue"),
          //   meta: {
          //     requiresAuth: true,
          //     name: "决策树回归"
          //   }
          // },
          {
            path: "fullyConnected", // 相对路径
            name: "fullyConnected",
            component: () => import("../views/traditional/fullyConnected.vue"),
            meta: {
              requiresAuth: true,
              name: "全连接网络"
            }
          }
        ]
      },

      // 您原有的异常页面子路由
      {
        path: "/error-pages", // 修改为更清晰的路径
        name: "ErrorPages",
        component: () => import("../views/empty-layout.vue"), // 可以是一个空的Layout组件或父级路由的占位符
        meta: {
          name: "异常页面",
        },
        children: [{
          path: "404", // 相对路径
          name: "404",
          component: () => import("../views/ErrorMessage/404.vue"),
          meta: {
            requiresAuth: true,
            name: "404",
          },
        },
        {
          path: "500", // 相对路径
          name: "500",
          component: () => import("../views/ErrorMessage/500.vue"),
          meta: {
            requiresAuth: true,
            name: "500",
          },
        },
        ],
      },
      {
        path: 'model-training', 
        name: 'ModelTraining', 
        component: () => import("../views/empty-layout.vue"),
        meta: {
          requiresAuth: true,
          name: '模型训练与评估', // 在侧边栏显示的主标题
        },
        children: [
          {
            path: 'dataset-partitioning', // 留空表示这是父路由的默认子路由，点击父级也会激活这个。
            name: 'DatasetSplitting', // 数据集划分的路由名称
            component: DataPreprocessingView,// 仍然指向同一个页面，内部根据meta或query参数判断展示内容
            meta: {
              requiresAuth: true,
              name: '数据处理与特征工程', // 子菜单显示标题
            },
            
          },
          {
            path: 'training-tuning', // 即使 url 是 /model-training，这里也可以有不同的path用于内部区分
            name: 'ModelTrainingAndTuning',
            component: () => import("../views/form/advancedForm.vue"),// 仍然指向同一个页面
            meta: {
              requiresAuth: true,
              name: '模型训练与参数调优',
            },
         
          },
          {
            path: 'evaluation-comparison', // 同样，不同的path可以用于内部区分
            name: 'ModelEvaluationAndComparison',
            component: () => import("../views/form/stepFrom.vue"), // 仍然指向同一个页面
            meta: {
              requiresAuth: true,
              name: '模型评估与比较',
            },
           
          }
        ]
      },

      // 您原有的AI助手页面
      {
        path: "/chat-ai", // 修改为更清晰的路径
        name: "ChatAI",
        component: () => import("../views/empty-layout.vue"), // 可以是一个空的Layout组件或父级路由的占位符
        meta: {
          name: "伏特加AI助手",
        },
        children: [{
          path: "assistant", // 相对路径
          name: "chat", // 建议这里使用更具描述性的name，或者保持唯一性，如 'ai-assistant'
          component: () => import("../views/chat/index.vue"),
          meta: {
            requiresAuth: true,
            name: "伏特加AI助手",
          },
        },
        ],
      },
    ],
  },
  // 可以添加一个 404 捕获路由，如果上面子路由没有匹配到的话
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('../views/ErrorMessage/404.vue') // 重用您的 404 组件
  }
];

const router = createRouter({
  history: createWebHashHistory(), // 沿用您当前的 Hash 模式
  routes,
});

export default router;